﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CntlImageViewer.ascx.vb"
    Inherits="WebUserControls_CntlImageViewer" %>
<script type="text/javascript">

    var ImgSource = new Array()
    var currentIndex = 0;

    function setArray() {

        ImgSource = dojo.query("img[id*='RptImages_ImgEvent']")
    }

    dojo.addOnLoad(
     function () {

         AttachEvent();
         setArray();
         var firsImage = dojo.query("*[id*='ImgEvent']")[0]

         var divSelectedImage = dojo.query("*[id$='ImgSelectedEvent']")[0]

         divSelectedImage.src = firsImage.src
     })

    function AttachEvent() {
        dojo.query("div[id*='ImgDiv']").forEach(function (tagElement) {
            dojo.connect(tagElement, "onclick", null, "ShowHide");
        });
    }

    function ShowHide(evt) {
        var divSelectedImage = dojo.query("*[id$='ImgSelectedEvent']")[0]
        divSelectedImage.src = evt.target.src
        var x = evt.target.id.split("_")[evt.target.id.split("_").length - 1]
        //	x = x.substring(0, x.indexOf("."))
        currentIndex = x * 1
        //  divSelectedImage.style.backgroundImage = divCurrentElement.childNodes[1].attributes.src
    }

    function ShowNext() {
        var divSelectedImage = dojo.query("*[id$='ImgSelectedEvent']")[0]
        if (currentIndex == ImgSource.length - 1)
            currentIndex = 0
        else
            currentIndex += 1

        divSelectedImage.src = ImgSource[currentIndex].src;
    }

    function ShowPrevious() {
        var divSelectedImage = dojo.query("*[id$='ImgSelectedEvent']")[0]
        if (currentIndex == 0)
            currentIndex = ImgSource.length - 1
        else
            currentIndex -= 1

        divSelectedImage.src = ImgSource[currentIndex].src;
    }

</script>
<a name="fb_share">Condividi l'album su facebook</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
</script>
<div style="height: 15px">
</div>
<div style="width: 30px; display: table-cell; vertical-align: middle" onclick="ShowPrevious()">
    <asp:Image ID="ImgPrev" runat="server" ImageUrl="../styles/images/indietro.jpeg" />
</div>
<div class="DivPaginaEvento" id='DivSelectedImage' style="display: table-cell">
    <asp:Image ID="ImgSelectedEvent" runat="server" />
</div>
<div style="width: 30px; display: table-cell; vertical-align: middle" onclick="ShowNext()">
    <asp:Image ID="ImgNext" runat="server" ImageUrl="../styles/images/avanti.jpeg" />
</div>
<br />
<div style="width: 30px; display: table-cell">
</div>
<div style="width: 780px; display: table-cell">
    <asp:Repeater ID="RptImages" runat="server">
        <ItemTemplate>
            <div id="ImgDiv" style="display: inline; width: 150px; cursor: pointer; background-repeat: no-repeat">
                <asp:Image ID="ImgEvent" Width="150px" runat="server" ImageUrl='<%# Container.DataItem %>' />
            </div>
        </ItemTemplate>
    </asp:Repeater>
</div>
<div style="width: 30px; display: table-cell">
</div>
